package com.java.star.novel.controller;

import cn.hutool.core.map.MapUtil;
import com.java.star.novel.core.bean.Result;
import com.java.star.novel.entity.Novel;
import com.java.star.novel.no.to.PageTO;
import com.java.star.novel.service.NovelService;
import com.java.star.novel.no.to.SearchTO;
import com.java.star.novel.vo.SearchNovelTable;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("novel")
@Api(description = "小说接口")
public class NovelController {

    @Autowired
    private NovelService novelService;

    @ApiOperation("获取首页标题展示块小说")
    @GetMapping("getIndexTitleBlockNovel_LX")
    public Result getIndexTitleBlockNovel_LX() {
        List<Novel> novelList = novelService.getIndexTitleBlockNovel_LX();
        return Result.ok().data(MapUtil.builder()
                .put("novelList", novelList).build());
    }

    @ApiOperation("获取首页轮播图小说")
    @GetMapping("getIndexSideshowNovel_XL")
    public Result getIndexSideshowNovel_XL() {
        List<Novel> novelList = novelService.getIndexSideshowNovel_XL();
        return Result.ok().data(MapUtil.builder()
                .put("novelList", novelList).build());
    }

    @GetMapping("/getSameKindRecommendNovel/{novelId}/{categoryId}")
    @ApiOperation(value = "获取同类推荐小说")
    public List<Novel> getSameKindRecommendNovel(@PathVariable int novelId, @PathVariable int categoryId){
        List<Novel> novelList = novelService.recommended(novelId,categoryId);
        return novelList;
    }

    @PostMapping("/ publishNovel")
    @ApiOperation(value = "发布小说")
    public Result publishNovel(@RequestBody Novel novel){
        Result result = novelService.publishNovel(novel);
        return result;
    }

    @GetMapping("/admin/novel/searchNovelTable")
    @ApiOperation(value = "查询小说表格")
    public SearchNovelTable searchNovelTable(SearchTO searchTO,PageTO page){
        SearchNovelTable searchNovelTable = novelService.searchNovelTable(searchTO,page);
        return searchNovelTable;
    }


}
